/**
 * 
 */
package com.hb.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hb.Constants;
import com.hb.dao.JobDao;
import com.hb.model.Job;
import com.hb.service.JobManager;

/**
 * @author Pham Hong Hung
 *
 */
@Service("jobManager")
public class JobManagerImpl extends GenericManagerImpl<Job, Long> implements
		JobManager {
	
	private JobDao jobDao;
	
	@Autowired
	public JobManagerImpl(JobDao jobDao) {
		super(jobDao);
		this.jobDao = jobDao;
	}

	@Override
	public List<Job> getJobs(Map<String, Object> map) {
		String queryName = "FROM Job j WHERE 1 = 1 ";
		if(map.get(Constants.JOB_NAME) != null){
			queryName += " AND j.name LIKE :" + Constants.JOB_NAME;
		}
		if(map.get(Constants.CATEGORY) != null){
			queryName += " AND j.category.id =:" + Constants.CATEGORY;
		}
		if(map.get(Constants.FROM_DATE) != null){
			queryName += " AND j.postDate >= :" + Constants.FROM_DATE;
		}
		if(map.get(Constants.TO_DATE) != null){
			queryName += " AND j.postDate <= :" + Constants.TO_DATE;
		}
		
		if(map.get(Constants.FROM_FEE) != null){
			queryName += " AND j.fee >= :" + Constants.FROM_FEE;
		}
		if(map.get(Constants.TO_FEE) != null){
			queryName += " AND j.fee <= :" + Constants.TO_FEE;
		}
		
		return this.jobDao.getByQueryString(queryName, map);
	}
}
